#!/bin/bash

# Simple install hook that errors the first time it is run, on any subsequent 
# run the hook will succeed (unless the canary file is removed).

canary_file=/tmp/resolver.canary
success_file=/tmp/resolver.success

function exit_error() {
    status-set blocked "Install hook failed on: $1 attempts." || true
    exit 1
}

if [ ! -e ${canary_file} ]; then
    echo "No canary file, exiting error."
    echo 1 > ${canary_file}
    exit_error 1
fi

# Need to error for x amount of times before juju stops trying automatically.
run_count=$(cat ${canary_file})

# For now juju is always re-trying. Need to just exit regardless.
echo $((${run_count}+1)) > ${canary_file}
exit_error ${run_count}

